package com.xgkj.diyiketang.activity;

import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.xgkj.diyiketang.EatShowApp;
import com.xgkj.diyiketang.ProtocolConst;
import com.xgkj.diyiketang.activity.data.DetailBmrGridAdapter;
import com.xgkj.diyiketang.activity.data.DetailFansAdapter;
import com.xgkj.diyiketang.data.EatShowUserInfo;
import com.xgkj.diyiketang.data.HuoDongInfo;
import com.xgkj.diyiketang.data.OrderInfo;
import com.xgkj.diyiketang.http.engine.ShowToastTaskEventListener;
import com.xgkj.diyiketang.http.engine.TaskEventListener;
import com.xgkj.diyiketang.task.BangDingShouJiTask;
import com.xgkj.diyiketang.task.BuildOrderTask;
import com.xgkj.diyiketang.task.GetVerifyCodeTask;
import com.xgkj.diyiketang.task.YiBaoMingListTask;
import com.xgkj.diyiketang.task.YueFanDetailTask;
import com.xgkj.diyiketang.task.YueZhiFuTask;
import com.xgkj.diyiketang.util.AlipayUtil;
import com.xgkj.diyiketang.util.DialogUtil;
import com.xgkj.diyiketang.util.EatShowSetting;
import com.xgkj.diyiketang.util.ImageCache;
import com.xgkj.diyiketang.util.PalLog;
import com.xgkj.diyiketang.util.ToastUtil;
import com.xgkj.diyiketang.util.ViewUtil;
import com.xgkj.diyiketang.util.WeiXinPay;
import com.xgkj.diyiketang.weidget.RoundImageView;
import com.xgkj.diyiketang.R;
import com.xgkj.diyiketang.wxapi.WXPayEntryActivity;

import org.w3c.dom.Text;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by XCKJ_Paladowow on 2016/4/14.
 */
public class YuFanDetailActivity extends BaseActivity implements View.OnClickListener {
    private Context mContex;
    private TextView back;
    private ImageButton mBaoming;
//    private ImageView lingqian_check;
//    private ImageView weixin_check;
//    private ImageView ali_check;
//    private RelativeLayout lingqian_layout;
//    private RelativeLayout weixin_layout;
   // private RelativeLayout ali_layout;
    private String mActiveId;
    private String mfaqirenId;
    private String mUsrLogo;
    private RoundImageView userLogo;
    private TextView mTitle;
    private TextView mZhuBoNick;
    private TextView mBaoMingQingKuang;
    private TextView mStartTime;
    private TextView mLastTime;
    private TextView mSexLimit;
    private TextView mFee;
    private TextView mAddress;
    private TextView mJianJie;
    //private EditText mPhone;
    private TextView mSellerName;
    private int yuefanDetailTaskId = -1;
    private int orderTaskId = -1;
    private HuoDongInfo hdinfo;
    private int yuezhifuTaskId = -1;
    private String mZhifuType = "";
    private String mObjectId;
    private String mMoney;
    private OrderInfo odinfo;
    private String mOrderNo;
//    private static final String ALIPAY_TYPE = "1";
//    private static final String WEIXINPAY_TYPE = "0";
//    private String orderTitle = "中国吃播";
//    private String orderBody = "中国吃播";
//    final IWXAPI msgApi = WXAPIFactory.createWXAPI(this, null);
//    private WeixinReceive mWeiXinReceive;
    private ProgressDialog mProgress;
//    private RelativeLayout mBmqkLayout;
//    private ProgressBar probar;
    private String mType;

    private RelativeLayout mButtonRayout;
    //private LinearLayout mGoneLayout;
    private TextView mBangDing;
    private ImageView mSellerPhone;
//
//    private EditText phoneEdit;
//    private EditText codeEdit;
//    private RelativeLayout mVfCodeLayout;
//    private static final int PHONE_LENGTH = 11;
//    private static final String PHONE_REGEX = "1[34578]\\d{9}";
//    private static final int CODE_LENGTH = 6;
    //private Button codeButton;
    //private TimeCount time;
    //private String mPhone;
//    private String mCode;
    private int getCodeTaskId = -1;
    private int bdPhoneTaskId = -1;
//    private String phoneIsNull;
//    private ImageView mLine;
    private TextView mCaipin;
    private TextView mTishiTime;
    private LinearLayout mHisZhuYe;
    private LinearLayout mChatTo;
    private TextView mFocusText;
    private ImageView mFocusImg;
    private ImageView sellerLogo;
    private String  sellerlogoUrl;
    //private RelativeLayout mBaoMingQKLayout;
    private LinearLayout mBmrLayout;
    private GridView bmrGrid;
    private DetailBmrGridAdapter dtfansAdapter;
    private int bmrTaskId = -1;
    private Button moreBmrBtn;
    private RelativeLayout mWeiZhiLayout;
    private String address;
    private String city;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yuefandetail);
//        time = new TimeCount(90000, 1000);
        mContex = this;
//        msgApi.registerApp(ProtocolConst.APP_ID);
        initView();
    }

    private void initView() {
        Intent intent = getIntent();
        mActiveId = intent.getStringExtra("ACTIVEID");
        mUsrLogo = intent.getStringExtra("LOGO");
        mType = intent.getStringExtra("TYPE");
        sellerlogoUrl = intent.getStringExtra("SELLERLOGO");
        mButtonRayout = (RelativeLayout) findViewById(R.id.bottom_layout);
//        mGoneLayout = (LinearLayout) findViewById(R.id.gone_type);
//        mLine = (ImageView) findViewById(R.id.gone_line);
        if(mType!=null&&mType.equals("WANGQI")){
            mButtonRayout.setVisibility(View.GONE);
//            mGoneLayout.setVisibility(View.GONE);

        }

        back = (TextView) findViewById(R.id.back);
        back.setOnClickListener(this);
      //  requestWindowFeature(Window.FEATURE_PROGRESS);
//        probar = (ProgressBar) findViewById(R.id.progressBar5);
        setProgressBarVisibility(true);
        sellerLogo = (ImageView) findViewById(R.id.logo);
        if (sellerlogoUrl != null && sellerlogoUrl.length()>0) {
            ImageCache.getInstance(mContext).loadBitmapToView(sellerLogo,sellerlogoUrl, ViewUtil.getImageSize(mContext,R.drawable.default_big_image));
            sellerLogo.setVisibility(View.VISIBLE);
        }else {
            sellerLogo.setVisibility(View.GONE);
        }
        mTitle = (TextView) findViewById(R.id.hd_title);
        mZhuBoNick = (TextView) findViewById(R.id.zhubo_nick);
        mBaoMingQingKuang = (TextView) findViewById(R.id.baomingqingkuang);
        mStartTime = (TextView) findViewById(R.id.kaishishijian);
        mLastTime = (TextView) findViewById(R.id.jiezhishijian);
        mSexLimit = (TextView) findViewById(R.id.shiyongrenqun);
        mFee = (TextView) findViewById(R.id.fee);
        mAddress = (TextView) findViewById(R.id.dizhi_detail);
        mJianJie = (TextView) findViewById(R.id.jianjie);
//        phoneEdit = (EditText) findViewById(R.id.phonenum);
//        codeEdit = (EditText) findViewById(R.id.bangding_code);
//
//        codeButton = (Button) findViewById(R.id.forget_code_button);
//        codeButton.setOnClickListener(this);
        mSellerName = (TextView) findViewById(R.id.shangjiaming);

        userLogo = (RoundImageView) findViewById(R.id.head_img);
//        userLogo.setOnClickListener(this);
        if (mUsrLogo != null && mUsrLogo.length() > 0) {
            ImageCache.getInstance(mContext).loadBitmapToView(userLogo, mUsrLogo, null);
        }

        mHisZhuYe = (LinearLayout) findViewById(R.id.hiszhuye);
        mHisZhuYe.setOnClickListener(this);
        mBaoming = (ImageButton) findViewById(R.id.baoming_btn);
        mBaoming.setOnClickListener(this);
//        lingqian_check = (ImageView) findViewById(R.id.lingqian_check);
//        lingqian_layout = (RelativeLayout) findViewById(R.id.lingqian_layout);
//        lingqian_layout.setOnClickListener(this);
//        weixin_check = (ImageView) findViewById(R.id.weixin_check);
//        weixin_layout = (RelativeLayout) findViewById(R.id.weixin_layout);
//        weixin_layout.setOnClickListener(this);
//        ali_check = (ImageView) findViewById(R.id.zhifubao_check);
//        ali_layout = (RelativeLayout) findViewById(R.id.zhifubao_layout);
//        ali_layout.setOnClickListener(this);
//        mBmqkLayout = (RelativeLayout) findViewById(R.id.faqiren_layout);
//        mBmqkLayout.setOnClickListener(this);

//        mVfCodeLayout = (RelativeLayout) findViewById(R.id.yanzhengma_layout);
            mCaipin = (TextView) findViewById(R.id.cpjieshao);
        mTishiTime = (TextView) findViewById(R.id.tishi_time);
        mChatTo = (LinearLayout) findViewById(R.id.hischat);
        mChatTo.setOnClickListener(this);
        mFocusImg = (ImageView) findViewById(R.id.isFocusImg);
        mFocusText = (TextView) findViewById(R.id.isFocusText);
        mSellerPhone = (ImageView) findViewById(R.id.seller_phone);
//        mBaoMingQKLayout = (RelativeLayout) findViewById(R.id.baomingqingkuang_layout);
//        mBaoMingQKLayout.setOnClickListener(this);

        mBmrLayout = (LinearLayout) findViewById(R.id.bmrlist_layout);
        bmrGrid = (GridView) findViewById(R.id.bmr_list);
        dtfansAdapter = new DetailBmrGridAdapter(mContext);
        bmrGrid.setAdapter(dtfansAdapter);
        moreBmrBtn = (Button) findViewById(R.id.more_bmr_list);
        mWeiZhiLayout = (RelativeLayout) findViewById(R.id.jucandidian_layout);
        mWeiZhiLayout.setOnClickListener(this);

        getDetail();
    }

//    @Override
//    protected void onResume() {
//        super.onResume();
//        yuefanDetailTaskId = -1;
//        getDetail();
//    }

    private void getDetail() {

        if (yuefanDetailTaskId != -1) {
            return;
        }
        YueFanDetailTask task = new YueFanDetailTask(mActiveId);
        task.addListener(yuefanDetailTask);
        yuefanDetailTaskId = getEatShowApp().getTaskManager().addTask(task);
    }

    private void getBmrList(){
        YiBaoMingListTask task = new YiBaoMingListTask(mActiveId);
        task.addListener(yuefanDetailTask);
        bmrTaskId = getEatShowApp().getTaskManager().addTask(task);
    }

    private void doYueZhifu() {
        if (yuezhifuTaskId != -1) {
            return;
        }
        YueZhiFuTask task = new YueZhiFuTask(mObjectId, "1", mMoney,null);
        task.addListener(yuefanDetailTask);
        yuezhifuTaskId = getEatShowApp().getTaskManager().addTask(task);
    }

    private void getOrder() {
        BuildOrderTask task = new BuildOrderTask(mObjectId, "1", mMoney, mZhifuType,null,null,null,null,null,null,null);
//        BuildOrderTask task = new BuildOrderTask("",  "1", money, channelType);
        task.addListener(yuefanDetailTask);
        orderTaskId = getEatShowApp().getTaskManager().addTask(task);
    }

//    private void getPhoneCode() {
//        GetVerifyCodeTask task = new GetVerifyCodeTask(mPhone, "2");
//        task.addListener(yuefanDetailTask);
//        getCodeTaskId = getEatShowApp().getTaskManager().addTask(task);
//        time.start();
//    }

//    private void doBangding() {
//        BangDingShouJiTask task = new BangDingShouJiTask(mPhone, mCode);
//        task.addListener(yuefanDetailTask);
//        bdPhoneTaskId = getEatShowApp().getTaskManager().addTask(task);
//    }


    private TaskEventListener yuefanDetailTask = new ShowToastTaskEventListener(this) {
        @Override
        public void handleTaskCompleted(int taskId, int result, Object data) {
            String localUid = null;
            if (getEatShowApp().getmUserInfo() != null){
                localUid = getEatShowApp().getmUserInfo().getUserId();
            }
            if (taskId == yuefanDetailTaskId) {
                hdinfo = (HuoDongInfo) data;
                mfaqirenId = hdinfo.getUserId();
//                            PalLog.e("创建人ID",mfaqirenId);
//                              PalLog.e("当前用户ID",localUid);
                if(localUid!=null&&mfaqirenId.equals(localUid)){
                    mButtonRayout.setVisibility(View.GONE);
//                    mGoneLayout.setVisibility(View.GONE);
                }
                    mTitle.setText(hdinfo.getActivityTitle());
                    mObjectId = hdinfo.getActivityId();
                    mMoney = hdinfo.getFee();
//                if(hdinfo.getPromiseDish()!=null){
//                    String caipin = URLDecoder.decode(hdinfo.getPromiseDish());
//                    mCaipin.setText(Html.fromHtml(caipin));
//                }
                String bmNum = hdinfo.getSignCount();
                String maxNum = hdinfo.getMaxCount();
                if(bmNum.equals(maxNum)){
                    mBaoming.setEnabled(false);
                    mBaoming.setImageResource(R.drawable.lijibaoming_hui);
                }
                mTishiTime.setText(hdinfo.getStartTime());
                if (hdinfo.getPromiseDish() != null) {
                    String temp = hdinfo.getPromiseDish().replace("\\n", "\n");
                    hdinfo.setPromiseDish(temp);
                    String caipin = hdinfo.getPromiseDish();
                    mCaipin.setVisibility(View.VISIBLE);
                    mCaipin.setText(caipin);
                }else {
                    mCaipin.setVisibility(View.GONE);
                }
//                PalLog.e("caipin",caipin);

                    if (hdinfo.getNickName() != null) {
                        try {
                            mZhuBoNick.setText(URLDecoder.decode(hdinfo.getNickName(), "utf-8"));
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
                    }
                    mBaoMingQingKuang.setText(hdinfo.getMaxCount()+"人"+"  "+"已报名:" + hdinfo.getSignCount()+"人");
                int c = Integer.parseInt(hdinfo.getSignCount());
                int max = Integer.parseInt(hdinfo.getMaxCount());
                int jindu = c*100/max;
                        //(Integer.parseInt(hdinfo.getSignCount())/Integer.parseInt(hdinfo.getMaxCount()))*10000;
                PalLog.e("参加人数",c+"");
                PalLog.e("最大人数",max+"");
                PalLog.e("进度", jindu + "");
//                probar.setProgress(jindu);

                    mStartTime.setText(hdinfo.getStartTime());
                    mLastTime.setText(hdinfo.getLastTime());
                    if (hdinfo.getSexLimit() != null) {
                        String sexNum = hdinfo.getSexLimit();
                        if (sexNum.equals("0")) {
                            mSexLimit.setText("无");
                        } else if (sexNum.equals("1")) {
                            mSexLimit.setText("限男性");
                        } else if (sexNum.equals("2")) {
                            mSexLimit.setText("限女性");
                        }
                    }
                if(!hdinfo.isFocus()){
                    mFocusText.setText("已关注");
                    mFocusImg.setBackgroundResource(R.drawable.yiguanzhu);
                }else {
                    mFocusText.setText("未关注");
                    mFocusImg.setBackgroundResource(R.drawable.weiguanzhu);
                }
                if(hdinfo.getTelephone()!=null){
                    mSellerPhone.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            DialogUtil.createDialog(mContext, -1, getString(R.string.prompt), "请拨打" + hdinfo.getTelephone(), getString(R.string.ok), getString(R.string.cancel), new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Intent call_intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + hdinfo.getTelephone()));
                                    startActivity(call_intent);
                                }
                            }, null);
                        }
                    });
                }

                    mFee.setText(hdinfo.getFee()+"元");
                    mAddress.setText(hdinfo.getAddress());
                    address = hdinfo.getAddress();
                city = hdinfo.getCity();
                    mJianJie.setText(hdinfo.getDescription());
//                     phoneIsNull = hdinfo.getPhoneNum();
//                    phoneEdit.setText(phoneIsNull);

//                if(phoneIsNull!=null){
//                    mVfCodeLayout.setVisibility(View.GONE);
//                    mLine.setVisibility(View.GONE);
//                }
//                if(hdinfo.getPhoneNum()==null){
//                    mBangDing = (TextView) findViewById(R.id.bangdingphone);
//                    mBangDing.setVisibility(View.VISIBLE);
//                    mBangDing.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View v) {
//                            Intent intent = new Intent(mContext,BangDingPhoneActivity.class);
//                            startActivityForResult(intent, 1);
//                        }
//                    });
//                }
                    mSellerName.setText(hdinfo.getBusinessName());

                getBmrList();

            } else if (taskId == yuezhifuTaskId) {
                if (data != null) {
                    odinfo = (OrderInfo) data;
                    mOrderNo = odinfo.getOrderNo();
                    Intent intent = new Intent(mContext, BaoMingChengGongActivity.class);
                    intent.putExtra("ORDERNO", mOrderNo);
                    intent.putExtra("FEE", mMoney);
                    startActivity(intent);
                    finish();
                }
            } else if (taskId == orderTaskId) {
                orderTaskId = -1;
                if (data != null) {
                    odinfo = (OrderInfo) data;
                }
                mOrderNo = odinfo.getOrderNo();
                mZhifuType = odinfo.getPayChannel();
//                if (mZhifuType.equals(ALIPAY_TYPE)) {
//                    doAliPay();
//
//                } else if (mZhifuType.equals(WEIXINPAY_TYPE)) {
//                    doWeixinPay();
//
//                }
            }else if(taskId == bdPhoneTaskId){
//                if(checkInput()){
//                    if (mZhifuType.equals("lingqian")) {
//                        doYueZhifu();
//                    } else {
//                        getOrder();
//                    }
//                }
            }else if (taskId == bmrTaskId) {
                if (data != null) {
                    List<OrderInfo> list = (List<OrderInfo>) data;
                    if (list != null && list.size() > 0) {
                        dtfansAdapter.updateData(list);
                        moreBmrBtn.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {

                                Intent fqIntent = new Intent(mContext,BaoMingRenListActivity.class);
                                fqIntent.putExtra("ACTIVEID",mActiveId);
                                fqIntent.putExtra("FQRID",mfaqirenId);
                                startActivity(fqIntent);
                            }
                        });
                    } else {
                        mBmrLayout.setVisibility(View.GONE);
                    }

                }
            }

        }

        @Override
        public void handleTaskError(int taskId, int errorCode, String errorMsg) {
            super.handleTaskError(taskId, errorCode, errorMsg);
            if (taskId == yuefanDetailTaskId) {
                yuefanDetailTaskId = -1;
            } else if (taskId == yuezhifuTaskId) {
                yuezhifuTaskId = -1;
            } else if (taskId == orderTaskId) {
                orderTaskId = -1;
            }
//            else if (taskId == getCodeTaskId) {
//                getCodeTaskId = -1;
//                time.cancelTime();
//            }
        }

        @Override
        public void handleTaskMessage(int taskId, Object data) {
            super.handleTaskMessage(taskId, data);
        }
    };

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.baoming_btn:
                Intent intent_liji = new Intent(mContext,LijibaomingActivity.class);
                intent_liji.putExtra("HUODONGINFO",hdinfo);
                startActivity(intent_liji);
//                if(phoneIsNull!=null){
//                    if(checkInput()){
//                        if (mZhifuType.equals("lingqian")) {
//                            doYueZhifu();
//                        } else {
//                            getOrder();
//                        }
//                    }
//                }else {
//                    if (checkInputVfCode()) {
//                        doBangding();
//                    }
//                }


                break;
//            case R.id.lingqian_layout:
//                mZhifuType = "lingqian";
//                lingqian_check.setVisibility(View.VISIBLE);
//                weixin_check.setVisibility(View.GONE);
//                ali_check.setVisibility(View.GONE);
//                break;
//            case R.id.weixin_layout:
//                mZhifuType = WEIXINPAY_TYPE;
//                weixin_check.setVisibility(View.VISIBLE);
//                lingqian_check.setVisibility(View.GONE);
//                ali_check.setVisibility(View.GONE);
//                break;
//            case R.id.zhifubao_layout:
//                mZhifuType = ALIPAY_TYPE;
//                ali_check.setVisibility(View.VISIBLE);
//                lingqian_check.setVisibility(View.GONE);
//                weixin_check.setVisibility(View.GONE);
//                break;
//            case R.id.baomingqingkuang_layout:
//                Intent fqIntent = new Intent(mContext,BaoMingRenListActivity.class);
//                fqIntent.putExtra("ACTIVEID",mActiveId);
//                fqIntent.putExtra("FQRID",mfaqirenId);
//                startActivity(fqIntent);
//                break;
//
//            case R.id.forget_code_button:
//                if (checkInputBeforeSMS()) {
//                    getPhoneCode();
//                }
//                break;
            case R.id.hiszhuye:
                Intent uint = new Intent(mContext,AnchorActivity.class);
                uint.putExtra("userId",mfaqirenId);
                startActivity(uint);
                break;
            case R.id.hischat:
                if(getEatShowApp().getmUserInfo()!= null) {
                    //TODO 发消息界面
                    String Uid = hdinfo.getUserId();
//                    String opid = userInfo.getOpenId();
//                    if (opid != null) {
//                        Uid = opid.toLowerCase();
//                    }

                    EatShowUserInfo myInfo = EatShowApp.getInstance().getmUserInfo();
                    String myId = TextUtils.isEmpty(myInfo.getOpenId()) ? myInfo.getUserId() : myInfo.getOpenId();
                    if (myId.equals(Uid)){
                        ToastUtil.showMessage(mContext,R.string.Cant_chat_with_yourself);
                        return;
                    }

                    Intent intent = new Intent(mContext, ChatActivity.class);
                    intent.putExtra("userId", Uid);
                    intent.putExtra("userNick", hdinfo.getNickName());
                    intent.putExtra("myLogo", EatShowApp.getInstance().getmUserInfo().getUserLogo());
                    intent.putExtra("fromLogo", hdinfo.getUserLogo());
                    mContext.startActivity(intent);
                }else{
                    Intent lintent = new Intent(mContext, LoginActivity.class);
                    mContext.startActivity(lintent);
                }
                break;

            case R.id.jucandidian_layout:
                Intent wInent = new Intent(mContext,MapActivity.class);
                wInent.putExtra("CITY",city);
                wInent.putExtra("ADDR",address);
                startActivity(wInent);
                break;
        }
    }


//
//    private boolean checkInputBeforeSMS() {
//        mPhone = phoneEdit.getText().toString();
//        if (TextUtils.isEmpty(mPhone) || mPhone.length() != PHONE_LENGTH
//                || !mPhone.matches(PHONE_REGEX)) {
//            Toast.makeText(mContext, R.string.no_phone, Toast.LENGTH_SHORT)
//                    .show();
//            return false;
//        }
//        return true;
//    }

//    private void doAliPay() {
//        AlipayUtil.doAlipay(alipayHandler, YuFanDetailActivity.this, mOrderNo, orderTitle, orderBody, mMoney);
//    }
//
//    private void doWeixinPay() {
//        if (!msgApi.isWXAppSupportAPI() || !msgApi.isWXAppInstalled()) {
//            ToastUtil.showMessage(mContext, R.string.need_weixin_app);
//            return;
//        }
//
//        if (mWeiXinReceive == null) {
//            mWeiXinReceive = new WeixinReceive();
//            IntentFilter filter = new IntentFilter();
//            filter.addAction(WXPayEntryActivity.WEIXIN_PAY_SUCCESS_ACTION);
//            registerReceiver(mWeiXinReceive, filter);
//        }
//        new WeiXinPay(msgApi, YuFanDetailActivity.this, mOrderNo, orderBody, mMoney);
//    }
//
//    private Handler alipayHandler = new Handler() {
//        @Override
//        public void handleMessage(Message msg) {
//            super.handleMessage(msg);
//        }
//    };
//
//    private void showProgress() {
//        if (mProgress == null) {
//            mProgress = DialogUtil.showProgressDialog(mContext, getString(R.string.get_pageinfo_loading), new DialogInterface.OnCancelListener() {
//                @Override
//                public void onCancel(DialogInterface dialog) {
//                    mProgress = null;
//                }
//            });
//        }
//    }

    private void dismissDialog() {
        if (mProgress != null && mProgress.isShowing()) {
            mProgress.dismiss();
            mProgress = null;
        }
    }

//    class WeixinReceive extends BroadcastReceiver {
//        @Override
//        public void onReceive(Context context, Intent intent) {
//            boolean isSuccess = intent.getBooleanExtra(ProtocolConst.WEIXINPAY_SUCCESS, false);
//            if (isSuccess) {
//                Intent wintent = new Intent(mContext, BaoMingChengGongActivity.class);
//                wintent.putExtra("ORDERNO", mOrderNo);
//                wintent.putExtra("FEE", mMoney);
//                startActivity(wintent);
//                finish();
//
//            } else {
//
//            }
//
//            if (mWeiXinReceive != null) {
//                unregisterReceiver(mWeiXinReceive);
//                mWeiXinReceive = null;
//            }
//        }
//    }

//    @Override
//    protected void onDestroy() {
//        super.onDestroy();
//        if (mWeiXinReceive != null) {
////            unregisterReceiver(mWeiXinReceive);
//            mWeiXinReceive = null;
//        }
//    }

//    private boolean checkInput() {
//
//        if (TextUtils.isEmpty(mZhifuType)) {
//            Toast.makeText(mContext, R.string.no_check_pay, Toast.LENGTH_SHORT)
//                    .show();
//            return false;
//        }
//        return true;
//    }

//    @Override
//    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//        super.onActivityResult(requestCode, resultCode, data);
//        if(data!=null){
//            String  pnum = data.getExtras().getString("PHONE");
//            mPhone.setText(pnum);
//        }
//
//    }


    /**
     * 方法作用：倒计时
     */
//    class TimeCount extends CountDownTimer {
//
//        // 参数依次为总时长,和计时的时间间隔
//        public TimeCount(long millisInFuture, long countDownInterval) {
//            super(millisInFuture, countDownInterval);
//        }
//
//        @Override
//        public void onFinish() {// 计时完毕时触发
//            codeButton.setText(mContext.getString(R.string.get_vfcode));
//            codeButton.setClickable(true);
//            codeButton.setEnabled(true);
//        }
//
//        @Override
//        public void onTick(long millisUntilFinished) {// 计时过程显示
//            codeButton.setClickable(false);
//            codeButton.setEnabled(false);
//            codeButton.setText(String.format(
//                    mContext.getString(R.string.get_vfcode_new),
//                    millisUntilFinished / 1000));
//        }
//
//        public void cancelTime() {// 取消计时
//            time.cancel();
//            codeButton.setText(mContext.getString(R.string.get_vfcode));
//            codeButton.setClickable(true);
//            codeButton.setEnabled(true);
//        }
//
//    }
//
//    private boolean checkInputVfCode() {
//        mCode = codeEdit.getText().toString();
//
//        if (TextUtils.isEmpty(mCode)
//                || mCode.length() != CODE_LENGTH) {
//            Toast.makeText(mContext, R.string.no_code, Toast.LENGTH_SHORT)
//                    .show();
//            return false;
//        }
//
//        return true;
//    }
}
